<template>
  <view style="height: 100vh">
    <getdatascrollview ref="getdatascrollview" :api="getdata">
      <template #default="{ list }">
        <u-navbar title="用户管理">
          <template #right>
            <view class="iconright" @click="$z.gopage('/pages/USearch/uadd')">
              <u-icon name="plus" color="#333" size="20"></u-icon>
            </view>
          </template>
        </u-navbar>
        <formz ref="formz" :data="data" :inputs="inputs"></formz>
        <view style="width: 200px; margin: 20rpx auto">
          <u-button type="primary" @click="search" :loading="loading">
            {{ $z.$t("搜索") }}
          </u-button>
        </view>
        <view v-if="!searchfalg">
          <useritem
            v-for="(item, key) in list"
            :key="key"
            :item="item"
          ></useritem>
        </view>
        <view v-else>
          <useritem
            v-for="(item, key) in searchlist"
            :key="key"
            :item="item"
          ></useritem>
        </view>
      </template>
    </getdatascrollview>
  </view>
</template>

<script>
  import json from "./json";
  import useritem from "./components/useritem.vue";
  export default {
    components: {
      useritem,
    },
    data() {
      return {
        loading: false,
        inputs: json.searchjson,
        searchlist: [],
        searchfalg: false,
        query: {},
        data: {},
      };
    },
    onLoad(query) {
      this.query = query;
      this.init();
    },
    methods: {
      async init() {
        if (this.query.pcs) {
          this.data = this.query;
          this.searchfalg = true;
          setTimeout(() => {
            this.search();
          }, 300);
        }
      },
      async getdata(query) {
        if (this.searchfalg) {
          return [];
        }
        return await this.$z.request("/USearch", {
          ...query,
          b_pt: 1,
        });
      },
      async search() {
        this.searchfalg = true;
        let data = await this.$refs.formz.validate();
        let searchdata = {
          ...data,
        };
        for (let key in searchdata) {
          if (searchdata[key] == "") {
            delete searchdata[key];
          }
        }
        this.$refs.getdatascrollview.status = "nomore";
        this.searchlist = await this.$z.request("/USearchDetailed", searchdata);
        console.log(data, "data");
      },
    },
  };
</script>

<style lang="scss" scoped>
  .iconright {
    width: 88rpx;
    height: 88rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: -26rpx;
  }
</style>
